package cn.wolfcode.luowowo.common.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 把日期转换为星期几
 */
public class DateToWeek {

    public static String dateToWeek(String datetime) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        //星期日到星期六
//        String[] weekDays = { "is_sun", "is_mon", "is_tue", "is_wed", "is_thr", "is_fri", "is_sat" };
        String[] weekDays = { "星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
        Calendar cal = Calendar.getInstance(); // 获得一个日历
        Date datet = null;
        if(datetime!=null) {
            try {
                datet = f.parse(datetime);
                cal.setTime(datet);
            } catch (Exception e) {
                e.printStackTrace();
            }
            int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
            if (w < 0)
                w = 0;
            return weekDays[w];
        }
        return null;
    }
}
